package com.maoke.mknews.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.maoke.mknews.R;
import com.maoke.mknews.bean.News;

import java.util.List;

/**
 * Created by Administrator on 2019/9/23.
 */

public class NewsListViewAdapter extends BaseAdapter{
    Context context;
    List<News.ResultBean.DataBean> beanList;

    public NewsListViewAdapter(List<News.ResultBean.DataBean> beanList,Context context){
        this.beanList = beanList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context,R.layout.news_list_item,null);
        TextView newsTitle = (TextView) convertView.findViewById(R.id.news_title);
        TextView newsAuthName = (TextView) convertView.findViewById(R.id.news_auth_name);
        TextView newsDate = (TextView) convertView.findViewById(R.id.news_date);
        ImageView thumImage = (ImageView) convertView.findViewById(R.id.news_thum);
        newsTitle.setText(beanList.get(position).getTitle()+"");
        newsAuthName.setText(beanList.get(position).getAuthor_name()+"");
        newsDate.setText(beanList.get(position).getDate()+"");
        Glide.with(context).load(beanList.get(position).getThumbnail_pic_s()+"").into(thumImage);
        return convertView;
    }
}
